<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2019/6/11
 * Time: 10:16
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IArticle;
use App\Http\Repositories\Services\IType;
use App\Http\Requests\Admin\ArticleInputDTO;
use App\Util\LayUiVo;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class ArticleController extends Controller
{
    public $articleService;
    public $typeService;

    public function __construct(IArticle $articleService, IType $typeService)
    {
        $this->articleService = $articleService;
        $this->typeService = $typeService;
    }

    public function page(Request $request){
        $search = [];
        $search['title'] = $request->get('title');
        $search['type_id'] = $request->get('type');
        $size = $request->get('size', 10);
        $dao = $this->articleService->lists($search, $request->get('page', 1), $size);
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(ArticleInputDTO $inputDTO){
        $this->articleService->store($inputDTO);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function update(ArticleInputDTO $inputDTO,$id){
        $this->articleService->update($inputDTO,$id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function state($id, $state) {
        $this->articleService->state($id, $state);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')],[],[]));
    }
}